(function(w, d){
	
	var eonfox = function(config){
		if( config && config.debug ){
			eonfox.prototype.debug = true;
		}
	};
	eonfox.prototype = {
		constructor : eonfox,
		
		//鏄惁寮€鍚皟璇曟ā寮�
		debug : false,
		
		
		//鎺ュ彛鍦板潃
		api_server_url : 'http://softstore.applinzi.com/',
		//api_server_url : 'http://api.kfzlm.com/index.php',
		
		//鏂囦欢鏈嶅姟鍣║RL
		file_server_url : 'http://img.eonfox.cc/',
		
		
		
		//浼氳瘽鍚嶇О
		session_name : 'Https_K_Eonfox_Session_ID',
		
		
		/**
		 * 閿欒妫€娴�
		 */
		error : function(){
			if(!w.FormData || !w.FormData.prototype.append){
				return "鎮ㄦ鍦ㄤ娇鐢ㄧ殑娴忚鍣ㄧ増鏈繃浣庯紝灏嗕笉鑳芥甯告祻瑙堝拰浣跨敤銆傝鍗囩骇IE10鐗堟湰浠ヤ笂锛屾垨鏇存崲娴忚鍣ㄣ€�";
			}
			
			return null;
		},
		
		
		
		/**
		 * JS鍔ㄦ€佷慨鏀规祻瑙堝櫒涓殑title
		 * 骞朵笖鍏煎寰俊锛�
		 * 鐢变簬寰俊娴忚鍣ㄥ彧鍦ㄩ〉闈㈤娆″姞杞芥椂鍒濆鍖栦簡鏍囬title锛屼箣鍚庡氨娌℃湁鍐嶇洃鍚� window.title鐨刢hange浜嬩欢銆�
		 * 鎵€浠ヨ繖閲屼慨鏀逛簡title鍚庯紝绔嬪嵆鍒涘缓涓€涓姹傦紝鍔犺浇涓€涓┖鐨刬frame锛岀敱浜庡姞杞藉悗绔嬪嵆灏辩Щ闄わ紝涔熶笉浼氬椤甸潰閫犳垚褰卞搷锛屼絾杩欐牱寰俊娴忚鍣ㄤ笂鐨則itle渚垮埛鏂颁簡銆�
		 * 
		 * @param {Object} t
		 */
		update_title : function(t){
			if( typeof t != 'string' && 
			typeof t != 'number' ){
				t = '';
			}
			
			if(document.title == t){
				return false;
			}
			
			//璁剧疆鏍囬
			document.title = t;
			var body = $('body');
			var iframe = $('<iframe src="https://www.baidu.com/" frameborder="0" hspace="0" vspace="0" scrolling="no" height="0" width="0" style="left:-99999px;position:absolute;"></iframe>');
			iframe.on('load',function() {
			  setTimeout(function() {
			      iframe.off('load').remove();
			  }, 0);
			}).appendTo(body);
			
		},
		
		
		
		
		
		/**
		 * 鑾峰彇宸oken
		 */
		left_token : function(){
			eonfox.prototype.submit({async : false});
			var token = localStorage.getItem(this.session_name);
			if( token ){
				token = (function(){try{ return jQuery.parseJSON(token);}catch(e){return false;}}());
			}
			if( (function(){try{ return token['session_left_token'];}catch(e){return false;}}()) ){
				return token['session_left_token'];
				}else{
					return '';
				}
		},
		
		
		
		/**
		 * 鎻愪氦闃熷垪
		 */
		submit_queue : {},
		
		
		
		/**
		 * 鎻愪氦鐧昏
		 * 
		 * @return	{String}	杩斿洖涓€涓櫥璁伴殢鏈烘爣璇�
		 */
		submit_register : function(){
			var register_id = false;
			do{
				var rand_id = Math.random();
				rand_id += ""+(new Date()).getTime();
				if(typeof eonfox.prototype.submit_queue[rand_id] == 'undefined'){
					register_id = rand_id;
					}
			}
			while(!register_id);
			
			eonfox.prototype.submit_queue[register_id] = ((new Date()).getTime()/1000);//璧嬪€兼槸 鏃堕棿鎴� 锛堢锛�,鐢ㄤ簬鏈夋晥鏃堕棿
			return register_id;
		},
		
		
		
		/**
		 * 鎻愪氦瀹屾垚鍚�
		 * 鍒犻櫎鐧昏鏍囪瘑
		 * 
		 * @param {String} register_id
		 */
		submit_done : function(register_id){
			if(typeof eonfox.prototype.submit_queue[register_id] != 'undefined'){
				delete eonfox.prototype.submit_queue[register_id];
			}
		},
		
		
		
		/**
		 * 鍒ゆ柇鏈夋晥鐨勬敞鍐屾爣璇嗘湁鍑犱釜
		 * 
		 * @return	{int}	杩斿洖涓€涓暣鏁�
		 */
		submit_length : function(){
			var s = 30;
			var length = 0;
			for(var i in eonfox.prototype.submit_queue){
				if( (eonfox.prototype.submit_queue[i] + s) < ((new Date()).getTime()/1000) ){
					//宸茬粡杩囦簡鏈夋晥鏈�
					delete eonfox.prototype.submit_queue[i];
				}else{
					length ++;
				}
			}
			
			return length;
		},
		
		
		
		
		
		/**
		 * 璇锋眰
		 * 鏆傛椂鍙敮鎸� POST
		 * 
		 * {
		 * 	url : this.api_server_url,榛樿鎺ュ彛鍦板潃
		 * 	data : {},
		 *  temp : false,鏄惁鍏抽棴token涓轰复鏃惰闂� 
		 * 	async : 鏄惁寮傛銆�(榛樿: true)
		 *  recursion 锛� 閫掑綊鎻愪氦銆傞粯璁alse銆傚鏋滀负true锛岄偅涔堝啀骞跺彂寮傛
		 *  callback : 鍥炶皟鍑芥暟銆�
		 *  progress :function(loaded[宸茬粡涓婁紶澶у皬鎯呭喌], total[鎬籡, percent[鐧惧垎姣擼);
		 * }
		 * 
		 * jquery涓悇涓簨浠舵墽琛岄『搴忓涓嬶細
		 * ajaxStart(鍏ㄥ眬浜嬩欢)
		 * beforeSend
		 * ajaxSend(鍏ㄥ眬浜嬩欢)
		 * success
		 * ajaxSuccess(鍏ㄥ眬浜嬩欢)
		 * error
		 * ajaxError (鍏ㄥ眬浜嬩欢)
		 * complete
		 * ajaxComplete(鍏ㄥ眬浜嬩欢)
		 * ajaxStop(鍏ㄥ眬浜嬩欢)
		 * 
		 * 
		 * @param {Object} config	閰嶇疆淇℃伅
		 */
		submit : function(config){
			if( eonfox.prototype.debug ){
				console.log("submit()浼犲叆鍙傛暟:", config);
			}
			
			//鍥炶皟鍑芥暟
			if( !config.callback || config.callback.constructor != Function ){
				config.callback = function(){};
			}
			
			//鏄惁寮傛
			if(typeof config.async == 'undefined') config.async = true;//榛樿true
			config.async = config.async? true : false;
			
			if(typeof config.url == 'undefined' || typeof config.url != 'string'){
				config.url = this.api_server_url;
			}
			
			var token = localStorage.getItem(this.session_name);
			if( token ){
				token = (function(){try{ return jQuery.parseJSON(token);}catch(e){return false;}}());
			}
			
			var right_data = new FormData();
			var left_data = new FormData();
			
			if( config.request && typeof config.request == "string"){
				right_data.append("data", config.request);
				left_data.append("data", config.request);
			}
			
			//鐢ㄦ埛浼犲叆鐨刣ata鏁版嵁
			if( config.data && typeof config.data == "object" ){
				for(var i in config.data){
					right_data.append(i, config.data[i]);
					left_data.append(i, config.data[i]);
				}
			}
			
			if( eonfox.prototype.debug ){
				console.log("post()锛歳ight_data銆乴eft_data:", right_data, left_data);
			}
			
			if( !config.temp ){
				if( !(function(){try{ return token['session_right_token'];}catch(e){return false;}}()) ){
					right_data.append("session", "start");
				}else{
					right_data.append("token", token['session_right_token']);
					
					left_data.append("session", "start");
					left_data.append("token", token['session_left_token']);
				}
			}
			
			
			//鑾峰彇鎻愪氦鏍囪瘑
			config.submit_register = eonfox.prototype.submit_register();
			
			//鎻愪氦璇锋眰
			var request = {
				//涓婁紶鏂囦欢蹇呰鍙傛暟
				processData: false,
				contentType: false,
				
				type: 'POST',
				async: config.async,
				url: config.url,
				complete : function(){
					//褰撹姹傚畬鎴愪箣鍚庤皟鐢ㄨ繖涓嚱鏁帮紝鏃犺鎴愬姛鎴栧け璐ャ€傛墽琛屾椂闂存瘮success鏅�
					eonfox.prototype.submit_done(config.submit_register);//瀹屾垚鎻愪氦鍚�
				},
				success : function(){},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					if(typeof XMLHttpRequest.responseJSON == 'object'){
						console.warn(textStatus, errorThrown);
						this.success(XMLHttpRequest.responseJSON);
					}
				},
				
			};
			
			if( config.progress && config.progress.constructor == Function ){
				request.xhr = function(){
					myXhr = $.ajaxSettings.xhr();
	                if(myXhr.upload){ // 妫€鏌ヤ笂浼犲睘鎬ф槸鍚﹀瓨鍦�
	                	
	                    myXhr.upload.addEventListener('progress', function(e){                            
	                        var loaded = e.loaded;                  		//宸茬粡涓婁紶澶у皬鎯呭喌 
	                        var total = e.total;                      		//闄勪欢鎬诲ぇ灏� 
	                        var percent = Math.floor(100*loaded/total);     //宸茬粡涓婁紶鐨勭櫨鍒嗘瘮  
	                        config.progress(loaded, total, percent);
	                        
	                        /*
	                        console.log("宸茬粡涓婁紶浜嗭細"+percent+"%");                 
	                        */
	                        
	                    }, false); // 鐢ㄤ簬澶勭悊涓婁紶鐨勮繘搴�
	                    
	                }
	                return myXhr;
				};
			}
		
			
			//鍙充护鐗�
			var right_token_post = function(right_data, left_data){
				request.data = right_data;
				request.success = function(success_data){
					if(typeof success_data != 'object'){
						success_data = (function(){try{ return jQuery.parseJSON(success_data);}catch(e){return false;}}());
					}
					if(typeof success_data != 'object'){
						console.warn("搴旂敤鎺ュ彛鍝嶅簲寮傚父");
						return config.callback(false);
					}
					
					//濡傛灉瀛樺湪璇锋眰浠ょ墝锛岀洿鎺ヨ繑鍥炴暟鎹�
					if( (function(){try{ return success_data['token'];}catch(e){return false;}}()) ){
						//鍌ㄥ瓨浠ょ墝
						eonfox.prototype.storage_token(success_data);
						//杩斿洖鍒板洖璋冨嚱鏁�
						return config.callback(success_data);
					}else{
						
						/**
						 * 杩欓噷鍙兘浼氭敹鍒板紓姝ュ苟鍙戠殑褰卞搷
						 * 澶氭鎻愪氦寮傛锛岃€岃繑鍥炵粨鏋滃苟涓嶄細鍚屾锛宼oken鐨勬湁鏁堟€т篃浼氬彈鍒板奖鍝�
						 * 鎵€浠ュ啀鍙充护鐗屾病鏈夎繑鍥炰护鐗屾暟鎹殑鏃跺€欙紝闇€瑕佸垽鏂槦鍒楃殑闅忔満鏍囪瘑
						 * 濡傛灉瀛樺湪澶氫釜鏍囪瘑锛岄偅涔堝綋 config.recursion 涓虹湡鏃讹紝灏卞己琛岄€掑綊
						 */
						var submit_length = eonfox.prototype.submit_length();
						if( submit_length > 1 ){
							console.warn("搴旂敤鎺ュ彛鎻愪氦闃熷垪骞跺彂涓暟锛�", submit_length);
							if( config.recursion ){
								return eonfox.prototype.submit(config);
							}else{
								return config.callback(success_data);
							}
						}else{
							//鍚﹀垯璇存槑娌℃湁杩欎釜浼氳瘽锛屽啀杩涜宸︿护鐗屾煡璇�
							return left_token_post(left_data);
						}
						
					}
				};
				if( eonfox.prototype.debug ){
					console.log("post()锛氬彸浠ょ墝鎻愪氦:", request);
				}
				$.ajax(request);
				
			};
			
			
			//宸︿护鐗�
			var left_token_post = function(left_data){
				request.data = left_data;
				request.success = function(success_data){
						if(typeof success_data != 'object'){
							success_data = (function(){try{ return jQuery.parseJSON(success_data);}catch(e){return false;}}());
						}
						if(typeof success_data != 'object'){
							console.warn("搴旂敤鎺ュ彛鍝嶅簲寮傚父");
							return config.callback(false);
						}
						//濡傛灉娌℃湁鎶ラ敊
						if( (function(){try{ return success_data['token'];}catch(e){return false;}}()) ){
							//鍌ㄥ瓨浠ょ墝
							eonfox.prototype.storage_token(success_data);
						}
						
						//杩斿洖鍒板洖璋冨嚱鏁�
						return config.callback(success_data);
				};
				
				if( eonfox.prototype.debug ){
					console.log("post()锛氬乏浠ょ墝鎻愪氦:", request);
				}
				
				$.ajax(request);
			};
			
			
			return right_token_post(right_data, left_data);
		},
		
		
		
		
		
		
		/**
		 * 鍌ㄥ瓨token
		 * 
		 * @param {Object} data
		 */
		storage_token : function(data){
			if( !data ){
				return false;
			}
			
			var token_data = null;
			var exist_right_token = false;
			var exist_left_token = false;
			
			exist_right_token  = (function(){try{ return data['token']['session_right_token'];}catch(e){return false;}}());
			exist_left_token  = (function(){try{ return data['token']['session_left_token'];}catch(e){return false;}}());
			if(exist_right_token && exist_left_token){
				token_data = data['token'];
			}else{
				//鏈夊彲鑳芥槸椤剁骇鍏宠仈瀵硅薄
				exist_right_token  = (function(){try{ return data['session_right_token'];}catch(e){return false;}}());
				exist_left_token  = (function(){try{ return data['session_left_token'];}catch(e){return false;}}());
				if(exist_right_token && exist_left_token){
					token_data = data;
				}
			}
			
			if(!token_data){
				return false;
			}
			
			//寮傛鍙兘瀛樺湪瑕嗙洊鐨勯棶棰橈紝鎵€浠ュ姣斿凡瀛樺湪鐨則oken,濡傛灉鍙冲乏鏈変竴涓浉鍚屽垯姣旇緝褰撳墠鏃堕棿锛屽嵆鏈€澶х殑褰撳墠鏃堕棿鏄渶鏂扮殑銆�
			var localStorage_token = localStorage.getItem(this.session_name);
			if( localStorage_token ){
				localStorage_token = (function(){try{ return jQuery.parseJSON(localStorage_token);}catch(e){return false;}}());
			}
			if( (function(){try{ return localStorage_token['session_right_token'];}catch(e){return false;}}()) && 
			(function(){try{ return localStorage_token['session_left_token'];}catch(e){return false;}}()) ){
				
				if(localStorage_token['session_right_token'] == token_data['session_right_token'] || 
				localStorage_token['session_left_token'] == token_data['session_left_token'] ){
					if( eonfox.prototype.debug ){
						console.log("闇€瑕佸姣旀棫token涓殑褰撳墠鏃堕棿鎴�,涓簍rue鍒欎笉闇€瑕佹洿鏂皌oken", localStorage_token['session_now_time'], token_data['session_now_time'], parseInt(localStorage_token['session_now_time']) > parseInt(token_data['session_now_time']));
					}
					if( parseInt(localStorage_token['session_now_time']) > parseInt(token_data['session_now_time']) ){
						if( eonfox.prototype.debug ){
							console.log("骞跺彂寮傛锛屼笉闇€瑕佹洿鏂皌oken" );
						}
						return false;
					}
					
				}
			}
			
			localStorage.setItem(this.session_name, JSON.stringify(token_data));
			return true;
		},
		
		
		
		
		
		/**
		 * 鑾峰彇鏂囦欢鐨勮矾鐢变俊鎭紝鐢ㄤ簬鍦ㄩ〉闈笂鏄剧ず
		 * file_url( $('[type="file"]')[0].files[0] );
		 * 
		 * @param {Object} file
		 */
		file_url : function(file){
			var url = "" ;
			try{
				if (window.createObjectURL != undefined) { // basic
					url = window.createObjectURL(file) ;
				} else if (window.URL != undefined) { // mozilla(firefox)
					url = window.URL.createObjectURL(file) ;
				} else if (window.webkitURL != undefined) { // webkit or chrome
					url = window.webkitURL.createObjectURL(file) ;
				}
			} catch (e){
				url = "" ;
			}
			
			return url ;
		},
		
		
		
		/**
		 * 瑙﹀彂鐐瑰嚮
		 * trigger_click( $('[type="file"]').get(0) );
		 * 
		 * @param {Object} obj
		 */
		trigger_click : function (obj){
			//鍏堝垽鏂槸鍚︽槸ie
		銆€銆€var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false; 
		銆€銆€if(ie){
				obj.click(); 
			}else{
				var a=document.createEvent("MouseEvents");//FF鐨勫鐞� 
				a.initEvent("click", true, true);  
				obj.dispatchEvent(a);
				}
			
		},
		
		
				
		/**
		 * JS鍔ㄦ€佷慨鏀规祻瑙堝櫒涓殑title
		 * 骞朵笖鍏煎寰俊锛�
		 * 鐢变簬寰俊娴忚鍣ㄥ彧鍦ㄩ〉闈㈤娆″姞杞芥椂鍒濆鍖栦簡鏍囬title锛屼箣鍚庡氨娌℃湁鍐嶇洃鍚� window.title鐨刢hange浜嬩欢銆�
		 * 鎵€浠ヨ繖閲屼慨鏀逛簡title鍚庯紝绔嬪嵆鍒涘缓涓€涓姹傦紝鍔犺浇涓€涓┖鐨刬frame锛岀敱浜庡姞杞藉悗绔嬪嵆灏辩Щ闄わ紝涔熶笉浼氬椤甸潰閫犳垚褰卞搷锛屼絾杩欐牱寰俊娴忚鍣ㄤ笂鐨則itle渚垮埛鏂颁簡銆�
		 * 
		 * @param {Object} t
		 * @param {Object} src	鍔犺浇涓€涓矾鐢便€備负绌哄垯榛樿涓虹櫨搴﹀湴鍧€
		 */
		title : function(t, src){
			if( typeof t != 'string' && 
			typeof t != 'number' ){
				t = '';
			}
			
			if(document.title == t){
				return false;
			}
			
			if(!src){
				src = "https://www.baidu.com/";
			}
			
			//璁剧疆鏍囬
			document.title = t;
			var body = $('body');
			var iframe = $('<iframe src="'+src+'" frameborder="0" hspace="0" vspace="0" scrolling="no" height="0" width="0" style="left:-99999px;position:absolute;"></iframe>');
			iframe.on('load',function() {
			  setTimeout(function() {
			      iframe.off('load').remove();
			  }, 0);
			}).appendTo(body);
			
		},
		
		
		
		
		
		/**
		 * 瀵笵ate鐨勬墿灞曪紝灏� Date 杞寲涓烘寚瀹氭牸寮忕殑String * 鏈�(M)銆佹棩(d)銆�12灏忔椂(h)銆�24灏忔椂(H)銆佸垎(m)銆佺(s)銆佸懆(E)銆佸搴�(q)
		 * 鍙互鐢� 1-2 涓崰浣嶇 * 骞�(y)鍙互鐢� 1-4 涓崰浣嶇锛屾绉�(S)鍙兘鐢� 1 涓崰浣嶇(鏄� 1-3 浣嶇殑鏁板瓧)
	     * (new cao).date("yyyy-MM-dd hh:mm:ss.S")==> 2006-07-02 08:09:04.423      
		 * (new cao).date("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 浜� 20:09:04      
		 * (new cao).date("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 鍛ㄤ簩 08:09:04      
		 * (new cao).date("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 鏄熸湡浜� 08:09:04      
		 * (new cao).date("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18  
		 * 
		 * timestamp 鏄竴涓绉掓椂闂存埑
		 */
		date : function(fmt, timestamp){
			if(timestamp){
				var time = new Date(timestamp);
				}else{
					var time = new Date();
					}
			
			var o = {         
		    "M+" : time.getMonth()+1, //鏈堜唤  锛屾敞鎰廽s閲岀殑鏈堣鍔�1        
		    "d+" : time.getDate(), //鏃�         
		    "h+" : time.getHours()%12 == 0 ? 12 : time.getHours()%12, //灏忔椂         
		    "H+" : time.getHours(), //灏忔椂         
		    "m+" : time.getMinutes(), //鍒�         
		    "s+" : time.getSeconds(), //绉�         
		    "q+" : Math.floor((time.getMonth()+3)/3), //瀛ｅ害         
		    "S" : time.getMilliseconds() //姣         
		    };         
		    var week = {         
		    "0" : "鏃�",         
		    "1" : "涓€",         
		    "2" : "浜�",         
		    "3" : "涓�",         
		    "4" : "鍥�",         
		    "5" : "浜�",         
		    "6" : "鍏�"        
		    };         
		    if(/(y+)/.test(fmt)){         
		        fmt=fmt.replace(RegExp.$1, (time.getFullYear()+"").substr(4 - RegExp.$1.length));         
		    }         
		    if(/(E+)/.test(fmt)){         
		        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "鏄熸湡" : "鍛�") : "")+week[time.getDay()+""]);         
		    }         
		    for(var k in o){         
		        if(new RegExp("("+ k +")").test(fmt)){         
		            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));         
		        }         
		    }         
		    return decodeURI(fmt);
		},
		
		
		
		
		
		
		
		
		
	};
	
	
	
	
	
	w.eonfox = function(config){
		return new eonfox(config);
	};
	
	w.eonfox.v = 'v1';//鐗堟湰鍙�



})(window, document);		


